package com.kobe.thread;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

/**
 * @作者：caopengfei
 * @时间：2020/9/14
 */
public class FutureTest {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executor = Executors.newFixedThreadPool(2);
        //创建一个Callable，3秒后返回String类型
        Callable myCallable = new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(3000);
                System.out.println("calld方法执行了");
                return "call方法返回值";
            }
        };


        Callable myCallable22 = new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(5000);
                System.out.println("calld方法执行了22");
                return "call方法返回值22";
            }
        };

        Callable myCallable333 = new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(4000);
                System.out.println("calld方法执行了22");
                return "call方法返回值22";
            }
        };
        List<Future> futureList = new ArrayList<>();
        futureList.add(executor.submit(myCallable));
        futureList.add(executor.submit(myCallable22));
        futureList.add(executor.submit(myCallable333));

    }

    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

}
